In three dimensional graphics, surfaces are typically rendered by assembling a plurality of polygons in a desired shape. The polygons (which are typically triangles) are defined by vertices, and each vertex is defined by three dimensional coordinates in world space, by color values, and by texture coordinates. Vertices can have other attributes, such as surface normals.
The surface determined by an assembly of polygons is typically intended to be viewed in perspective. To display the surface on a computer monitor, the three dimensional world space coordinates of the vertices are transformed into screen coordinates in which horizontal and vertical values (x, y) define screen position and a depth value z determines how near a vertex is to the screen and thus whether that vertex is viewed with respect to other points at the same screen coordinates. The color values define the brightness of each of red/green/blue (r, g, b) color at each vertex and thus the color (often called diffuse color) at each vertex. Texture coordinates (u, v) define texture map coordinates for each vertex on a particular texture map defined by values stored in memory.
The world space coordinates for the vertices of each polygon are processed to determine the two-dimensional coordinates at which those vertices are to appear on the two-dimensional screen space of an output display. If a triangle's vertices are known in screen space, the positions of all pixels of the triangle vary linearly along scan lines within the triangle in screen space and can thus be determined. Typically, a rasterizer uses (or a vertex processor and a rasterizer use) the three-dimensional world coordinates of the vertices of each polygon to determine the position of each pixel of each surface (“primitive” surface”) bounded by one of the polygons.
The color values of each pixel of a primitive surface (sometimes referred to herein as a “primitive”) vary linearly along lines through the primitive in world space. A rasterizer performs (or a rasterizer and a vertex processor perform) processes based on linear interpolation of pixel values in screen space, linear interpolation of depth and color values in world space, and perspective transformation between the two spaces to provide pixel coordinates and color values for each pixel of each primitive. The end result of this is that the rasterizer outputs a sequence red/green/blue color values (conventionally referred to as diffuse color values) for each pixel of each primitive.
One or more of the vertex processor, the rasterizer, and a texture processor compute texture coordinates for each pixel of each primitive. The texture coordinates of each pixel of a primitive vary linearly along lines through the primitive in world space. Thus, texture coordinates of a pixel at any position in the primitive can be determined in world space (from the texture coordinates of the vertices) by a process of perspective transformation, and the texture coordinates of each pixel to be displayed on the display screen can be determined. A texture processor can use the texture coordinates (of each pixel to be displayed on the display screen) to index into a corresponding texture map to determine texels (texture color values at the position defined by the texture coordinates for each pixel) to vary the diffuse color values for the pixel. Often the texture processor interpolates texels at a number of positions surrounding the texture coordinates of a pixel to determine a texture value for the pixel. The end result of this is that the texture processor generates data determining a textured version of each pixel (of each primitive) to be displayed on the display screen.
A texture map typically describes a pattern to be applied to a primitive to vary the color of each pixel of the primitive in accordance with the pattern. The texture coordinates of the vertices of the primitive fix the position of the vertices of a polygon on the texture map and thereby determine the texture detail applied to each of the other pixels of the primitive in accordance with the pattern.
A texture applied to a surface in space can have a wide variety of characteristics. A texture can define a pattern such as a stone wall. It can define light reflected from positions on the surface. It can describe the degree of transparency of a surface and thus how other objects are seen through the surface. A texture can provide characteristics such as dirt or scratches which make a surface appear more realistic. A number of other variations can be provided which fall within the general description of a texture. In theory, a number of different textures can be applied to the pixels of any primitive. Some graphics processors capable of applying multiple textures to the pixels of a primitive progress through a series of steps in which data describing the pixels of each primitive are generated, a first texture is mapped to the pixels of the primitive using the texture coordinates of the vertices, texels to be combined with each pixel of the primitive (to vary the color of each such pixel in accordance with the first texture) are generated or retrieved, the texels describing the first texture and the color data for the pixels of the primitive are blended to generate textured pixel data. Then, an additional texture is mapped to the same primitive using the texture coordinates of the vertices, texels for the additional texture are generated or retrieved, and the texels describing the additional texture are blended with the previously generated textured pixel data to generate multiply textured pixel data.
U.S. Pat. No. 6,333,744, issued on Dec. 25, 2001 and assigned to the assignee of the present application, describes a graphics processor including a pipelined pixel shader that can be operated to blend multiple textures with each pixel of a primitive in a single pass through the pipeline.
Some conventional pipelined pixel shaders can recirculate data through their stages. For example, to apply N textures (where N=1 or N=2) to each pixel of a primitive, such a pixel shader operates in response to a program to pass each pixel once through each stage. To apply 2N textures to each pixel of the same primitive, the shader operates in response to another program to pass each pixel once through each stage (to generate partially textured pixels by combining first texture data with each pixel) and then recirculate each partially textured pixel through the shader (by passing each partially textured pixel through each stage a second time) to combine additional texture data with each partially textured pixel.
Until the present invention, a pipelined pixel shader had not been designed with a scalable architecture in the sense that it could be implemented in modular fashion with any number of pipelined processing stages and still be operable in response to the same program (regardless of the number of stages). The inventors have recognized how to design a pipelined pixel shader with a scalable architecture so that it can be implemented with a low number of identical processing stages for applications in which it is acceptable to operate the pixel shader (in response to a program) with a high degree of data recirculation through each stage in order to perform a large number of texturing operations on each pixel, or with a high number of the same processing stages for applications in which it is desired to operate the pixel shader (in response to the same program) with no more than a low degree of data recirculation through each stage in order to perform the same number of texturing operations on each pixel.
Nor had a pipelined pixel shader been designed, until the present invention, to have a scalable architecture and also to be capable of executing conditional jumping and branching, looping, and other high-level flow control constructs. Nor had a pipelined pixel shader been designed, until the present invention, with each of its processing stages having a modular design so that each processing stage can be implemented in a scalable manner to include any number of identical pipelined instruction execution stages and be operable to execute the same sequence of instructions regardless of the number of instruction execution stages.